package com.betterjr.modules.risk.loan.data;

import java.util.ArrayList;
import java.util.List;

import com.betterjr.common.utils.Collections3;
import com.betterjr.modules.customer.entity.CustMechBankAccount;
import com.betterjr.modules.risk.loan.dao.FillBankAbstract;
import com.betterjr.modules.risk.loan.entity.LoanProjectBank;
import com.betterjr.modules.risk.loan.entity.LoanProjectRelation;

public class FillBankFactory {

    private static List<FillBankAbstract> bankImpl = new ArrayList<>(16);

    static {
        bankImpl.add(new CustAccountRegulatoryFillBank());
        bankImpl.add(new CustAggreationFillBank());
        bankImpl.add(new CustGatheringFillBank());
        bankImpl.add(new CustPayServiceFillBank());
        bankImpl.add(new CustWithHoldInterestFillBank());
        bankImpl.add(new CustWithHoldPrinpalFillBank());
        bankImpl.add(new FactoryGatheringInterestFillBank());
        bankImpl.add(new FactoryGatheringPrincipalFillBank());
        bankImpl.add(new FactoryLoanFillBank());
    }

    public static void addBank(FillBankAbstract bank) {

        if (bankImpl != null && !bankImpl.contains(bank)) {
            bankImpl.add(bank);
        }
    }

    public static void removeBank(FillBankAbstract bank) {

        if (bankImpl != null && !bankImpl.contains(bank)) {
            bankImpl.remove(bank);
        }

    }

    public static void invoke(LoanProjectRelation anLoan, List<LoanProjectBank> banks) {

        if (anLoan != null && !Collections3.isEmpty(banks)) {

            for (LoanProjectBank bank : banks) {
                for (FillBankAbstract fillBank : bankImpl) {
                    if (fillBank.fillBank(anLoan, bank)) break;
                }
            }

        }

    }

    public static void invokeFromFront(LoanProjectRelation anLoan, List<CustMechBankAccount> accountList) {

        if (anLoan != null && !Collections3.isEmpty(accountList)) {

            for (FillBankAbstract fillBank : bankImpl) {
                fillBank.fillBank(anLoan, accountList);
            }

        }

    }
}
